<?php
class UbigeosController extends AppController {
	var $name = 'Ubigeos';
	var $components = array('RequestHandler');
	
	function index(){
		$this->layout="ajax";		
		
		if($this->JQGridPaginate->isGrid){
			//$fields = array('Ubigeo.id','Ubigeo.codigo','Ubigeo.descripcion','"Ubigeo"."created"::date AS "Ubigeo__created"','"Estado"."descripcion" AS "Ubigeo__estado"');
			$fields = array('Ubigeo.id','Ubigeo.ubigeo','Ubigeo.distrito','Ubigeo.provincia'
			,'Ubigeo.departamento'
			,'"Estado"."descripcion" AS "Ubigeo__estado"');
			$this->JQGridPaginate->recursive = 0;
			$this->JQGridPaginate->cakefields = $fields;
			echo $this->JQGridPaginate->paginate("Ubigeo");
			$this->autoRender = false;
		}
		else
			if($this->RequestHandler->isPost()){	
				$oper = $this->params['form']['oper'];
				if($oper == "add"){
					$this->Ubigeo->create();				 
				}elseif ($oper == "edit"){
					$this->data['Ubigeo']['id'] = $this->params['form']['id'];
				}elseif ($oper == "del"){
					$this->data['Ubigeo']['id'] = $this->params['form']['id'];
					$this->data['Ubigeo']['estado_id'] = 2;				
				}
				
				$this->Ubigeo->save($this->data['Ubigeo']);
				$this->autoRender = false;			
			}
	}
	
	function listaubigeos(){
		$this->layout="ajax";
		$listaUbigeos = $this->Ubigeo->getUbigeoLista();
		echo json_encode($listaUbigeos);
		$this->autoRender = false;
	}
}